﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XSTDZ.ERP.Domain.Models
{
    /// <summary>
    /// 部门
    /// </summary>
    public partial class Dept
    {
        public Dept()
        {
            this.Users = new HashSet<User>();
            this.Depts = new HashSet<Dept>();
        }
        public Dept InitDept(Dept dept)
        {
            if (Guid.Equals(dept.ParentID, Guid.Empty))
            {
                dept.ParentID = dept.Id;
                dept.Level = 1;
            }
            else
            {
                if (this.Parent!=null)
                {
                    this.Level = Convert.ToSByte(this.Parent.Level + 1);
                }
            }
            if (this.Level==null||this.Level <= 1)
            {
                this.Level = 1;
            }
            if (this.Order <= 0)
            {
                this.Order = 0;
            }
            return this;
        }
        /*
         /// <summary>
         /// 设置部门所属组织机构
         /// </summary>
         /// <param name="org">指定组织机构</param>
         /// <returns>部门</returns>
         public Dept SetOrg(Org org)
         {
             if (this.Org.Depts.Contains(this))
             {
                 this.Org.Depts.Remove(this);
             }
             this.Org = org;
             org.AddChildDept(this);
             return this;
         }
          /// <summary>
         /// 添加子部门
         /// </summary>
         /// <param name="dept">指定部门</param>
         /// <returns>部门</returns>
         public Dept AddChildDept(Dept dept)
         {
             if (!this.Depts.Contains(dept))
             {
                 dept.Parent = this;
                 this.Depts.Add(dept);
             }
             return this;
         }
         /// <summary>
         /// 重置父级部门
         /// </summary>
         /// <param name="parentDept">指定父级部门</param>
         /// <returns>部门</returns>
         public Dept ResetParentDept(Dept parentDept)
         {
             this.Parent.Depts.Remove(this);
             this.Parent = parentDept;
             return parentDept.AddChildDept(this);
         }
         */
    }
}
